

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加账单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css">
    <script src="../js/jquery-1.4.1.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="#" lay-filter="component-form-group">
                <br>
                <h1>添加账单</h1>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <select name="typeId" lay-filter="aihao">
                            <option value=""></option>
                            <option value="1">收入</option>
                            <option value="2" >支出</option>
                            <option value="3">借入</option>
                            <option value="4">借出</option>
                        </select>
                    </div>
                </div>
                <br>
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <br>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="billTime" id="LAY-component-form-group-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <br>
                <div class="layui-form-item">
                    <label class="layui-form-label">金额</label>
                    <div class="layui-input-block">
                        <input type="text" name="price" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <br>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">说明</label>
                    <div class="layui-input-block">
                        <textarea name="explain" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>
                <br>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit lay-filter="formDemo2">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });


        /* 监听指定开关 */
        // form.on('switch(component-form-switchTest)', function(data){
        //     layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        // });

        /* 监听提交 */
        form.on('submit(formDemo2)', function(data){
            $.ajax({
                url:"http://localhost:10010/bill/add",
                async: false,
                type:"POST",
                dataType: "jsonp",
                jsonp:"callback",
                jsonpCallback:"success_jsonp",
                data:data.field,
                success: function(data){
                    if (data.msg=='1'){
                        alert("添加成功");
                        location.href='add.html';
                    }else{
                        alert("添加失败");
                        location.href='add.html';
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
